import Dialog from '@/components/dialog/index'
import Vue from 'vue'

export default {
  install(vue, options) {
    vue.prototype.$dataset = function (e) {
      let {currentTarget} = e
      if (currentTarget && currentTarget.dataset) return currentTarget.dataset
      return {}
    }

    /**
     * Promise版uni-app的toast
     * @param {string} message
     * @param {number} duration
     * @param {string} icon
     * @return {Promise<void>}
     */
    vue.prototype.$toast = (message, icon = 'none', duration = 1500) => {
      return new Promise((resolve, reject) => {
        Vue.prototype.uni.showToast({
          title: message,
          duration,
          icon,
          complete() {
            setTimeout(() => resolve(), duration)
          }
        });
      })
    }
  }
}